<?php

    //Sub Table Class define
    include_once("ClassSub.php");

class SalesDataClass
{
	var $REAgent;
	var $REOffice;
	var $ContractDate;
	var $ClosePrice;
    var $CloseDate;

	var $ID;
	
	function AddItemFromXML($XmlArray)
	{
		$Array = $XmlArray->children();
			
	 	$this->REAgent = $Array[0];
		$this->REOffice = $Array[1];
	 	$this->ContractDate = $Array[2];
	 	$this->ClosePrice = new CurrencyFormatClass;
		$this->ClosePrice->AddItemFromXML($Array[3]);
		$this->CloseDate = $Array[4];
	}
	
	function InsertSQL()
	{
		$this->ClosePrice->InsertSQL();		

		$strSqlCommand = "INSERT INTO SalesData( REAgentID, REOfficeID, ";
		$strSqlCommand .="ContractDate, ClosePrice, CloseDate) ";
		$strSqlCommand .= "VALUES( '".$this->REAgent."', ";
		$strSqlCommand .= "'".$this->REOffice."', ";
		$strSqlCommand .= "'".$this->ContractDate."', ";
		$strSqlCommand .= "'".$this->ClosePrice->ID."', ";
		$strSqlCommand .= "'".$this->CloseDate."') ";
				
		mysql_query($strSqlCommand);
		$this->ID = mysql_insert_id();		
	}
	
	function ModifySQL( $InputID )
	{
		$this->ID = $InputID;

		$strSqlCommand = "SELECT * FROM SalesData ";
		$strSqlCommand .= " WHERE idSalesData = '".$this->ID."' ";
		$result = mysql_query($strSqlCommand);
		$rowListingData = @mysql_fetch_array($result);

		$strSqlCommand =  "UPDATE SalesData SET ";
		$strSqlCommand .= "REAgentID='"			.$this->REAgent			."', ";
		$strSqlCommand .= "REOfficeID='"		.$this->REOffice		."', ";
		$strSqlCommand .= "ContractDate='"		.$this->ContractDate	."', ";
		$strSqlCommand .= "CloseDate='"			.$this->CloseDate		."' ";
		$strSqlCommand .= "WHERE idSalesData = ".$this->ID;
		mysql_query($strSqlCommand);

		$this->ClosePrice->ModifySQL( $rowListing["ClosePrice"]);			
	}		
}

?>